package top.lenjon.lib.model;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * @author wei
 * @since 2020/11/7 19:13
 */
public class ResponseModel implements Serializable {

    /**
     * 状态码
     */
    private int code;

    /**
     * 返回描述
     */
    private String message;

    /**
     * 数据部分
     */
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    ResponseModel(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

    public static ResponseModel success(String message, Object object) {
        return new ResponseModel(200, message, object);
    }

    public static ResponseModel success(String message) {
        return new ResponseModel(200, message, null);
    }

    public static ResponseModel error(String message, Object object) {
        return new ResponseModel(500, message, object);
    }

    public static ResponseModel error(String message) {
        return new ResponseModel(500, message, null);
    }
}
